/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.ui.form;

import com.rcnss.ui.form.command.CommandLogin;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import java.util.Locale;

/**
 *
 * @author Guesmi
 */
public class AppLoginForm extends VerticalLayout {
    private com.vaadin.ui.LoginForm login = new LoginForm();
    
    private Button bSubscribe = new Button("Inscription...");
    public AppLoginForm()
    {
    
    }

    @Override
    public void attach()
    {
        super.attach();
        initLogin();
        initSubscribe();
    }

    public void initLogin()
    {
        login.setSizeUndefined();
        CommandLogin loginAction = new CommandLogin(getWindow());
        login.addListener(loginAction);
        login.setCaption("Authentification");
        login.setDescription("<p>Cette Application necessite une authentification pour l'acceder, sinon, " +
                "vous pouvez envoyer une demande d'inscription</p>");
        login.setImmediate(true);
        login.setLocale(Locale.FRENCH);
        login.setStyleName("");
        this.addComponent(login);
    }
    public void initSubscribe()
    {
        bSubscribe.setStyleName(Button.STYLE_LINK);
        bSubscribe.addListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
                Window subsWindow = new Window("Inscription");
                ((VerticalLayout)subsWindow.getContent()).addComponent(new SubscribeFrom());
                ((VerticalLayout)subsWindow.getContent()).setSizeUndefined(); // For Auto-size
                subsWindow.setModal(true);
                getWindow().addWindow(subsWindow);
            }
        });
        this.addComponent(bSubscribe);
    }
}
